//订单查询
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            storeOrderCartReturnInfo: {
                orderCarts: [],
                total: 0,
                records: 1,
                orderDetail: false,
                conditions: {
                    cartId: '',
                    state: '',
                    prodName: '',
                    mallApiCode:'queryStoreOrderCartReturnBmoImpl'
                },
                curOrderCart: {}
            }
        },
        _initMethod: function() {
            $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function() {
            vc.on('storeOrderCartReturn', 'goBack', function(_param) {
                $that.storeOrderCartReturnInfo.orderDetail = false;
            });
            vc.on('storeOrderCartReturn', 'list', function() {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function(_currentPage) {
                $that._listOrders(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listOrders: function(_page, _rows) {
                $that.storeOrderCartReturnInfo.conditions.page = _page;
                $that.storeOrderCartReturnInfo.conditions.row = _rows;
                let param = {
                    params: $that.storeOrderCartReturnInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/mall.getAdminMallOpenApi',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartReturnInfo.total = _json.total;
                        $that.storeOrderCartReturnInfo.records = _json.records;
                        $that.storeOrderCartReturnInfo.orderCarts = _json.data;

                        let _orderCarts = $that.storeOrderCartReturnInfo.orderCarts;

                        _orderCarts.forEach(item => {
                            let _productSpecDetails = item.productSpecDetails;
                            let _specValue = '';
                            _productSpecDetails.forEach(detail => {
                                _specValue += (detail.detailValue + "/");
                            });

                            item.specValue = _specValue;
                        });

                        vc.emit('pagination', 'init', {
                            total: $that.storeOrderCartReturnInfo.records,
                            dataCount: $that.storeOrderCartReturnInfo.total,
                            currentPage: _page
                        });
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _queryOrdersMethod: function() {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _closeStoreOrderCartModal: function() {
                $("#storeOrderCartReturnModal").modal('hide');
            },
        }
    });
})(window.vc);